public class test7 {
    //请完成以下多线程编程：顺序打印
    //有三个线程，线程名称分别为：a，b，c。
    //每个线程打印自己的名称。
    //需要让他们同时启动，并按 c，b，a的顺序打印
    public static Object locker1=new Object();
    public static Object locker2=new Object();
    public static Object locker3=new Object();
    public static void main1(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            try{
                synchronized (locker1){
                    locker1.wait();
                }
                System.out.println(Thread.currentThread().getName());
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        },"a");
        Thread t2=new Thread(()->{
            try{
                synchronized (locker2){
                    locker2.wait();
                }
                System.out.println(Thread.currentThread().getName());
                synchronized (locker1){
                    locker1.notify();
                }
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        },"b");
        Thread t3=new Thread(()->{
            try{
                synchronized (locker3){
                    locker3.wait();
                }
                System.out.println(Thread.currentThread().getName());
                synchronized (locker2){
                    locker2.notify();
                }
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        },"c");
        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(1000);
        synchronized (locker3) {
            locker3.notify();
        }
    }
    public static void main(String[] args) throws InterruptedException {
        Thread[] threads = new Thread[3];
        for (int i = 0; i < 3; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println("我是一个线程，我的名字是："+Thread.currentThread());
                }
            },i+1+"");
        }
        threads[2].start();
        threads[2].join();
        threads[1].start();
        threads[1].join();
        threads[0].start();

    }
}

